import { PageDateSelect } from '@/types/pages/enum';
import axios from 'axios';
import qs from 'qs';
import { IPieChart,IChartData, ISale, ISaleFull } from '@/types/pages/salesAnalysis/interface';
import {IDateLineChart,IDatePieChart} from '@/types/echart'
import Mock from 'mockjs'

export const getSelesData:(type:PageDateSelect,date?:Date)=>Promise<ISale>=function(type:PageDateSelect,date?:Date){
    return new Promise((res,rej)=>{
      let data=Mock.mock({name:'销售量', unit:'万元', saleNum:'143923', saleRate:'24%',comparisonText:'比去年',upDownStatus:false,  totalNum:'500000'})
        if(type===PageDateSelect.mounth){
          data=Mock.mock({name:'销售量', unit:'万元', saleNum:'3923', saleRate:'14%',comparisonText:'比去年',upDownStatus:false,  totalNum:'42000'})
        }
        if(type===PageDateSelect.day){
          data=Mock.mock({name:'销售量', unit:'万元', saleNum:'123', saleRate:'30%',comparisonText:'比去年',upDownStatus:false,  totalNum:'3000'})
        }

        res(data);
    })

}

export const getSelesMoney:(type:PageDateSelect,date?:Date)=>Promise<ISale>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{

        let data=Mock.mock({name:'销售量', unit:'吨',  saleNum:'243923', saleRate:'24%','upDownStatus|1-2':true ,totalNum:'500000'})
        if(type===PageDateSelect.mounth){
          data=Mock.mock({name:'销售量', unit:'吨', saleNum:'3923', saleRate:'14%',comparisonText:'比去年',upDownStatus:false,  totalNum:'42000'})
        }
        if(type===PageDateSelect.day){
          data=Mock.mock({name:'销售量', unit:'吨', saleNum:'123', saleRate:'30%',comparisonText:'比去年',upDownStatus:false,  totalNum:'3000'})
        }
        res(data);
    })

}

export const getPieLeftChart:(type:PageDateSelect,date?:Date)=>Promise<IDatePieChart>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{

      const dataset:IDatePieChart={title:'产品类别销售占比1',dataset:{dimensions:['成分','价格'],'source':[{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,}]}}
        res(Mock.mock(dataset));
    })
}
export const getPieRightChart:(type:PageDateSelect,date?:Date)=>Promise<IDatePieChart>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{
      const dataset={title:'产品类别销售占比',dataset:{dimensions:['成分','价格'],'source':[{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,}]}}

        // const data=Mock.mock({title:'产品类别销售占比',datas:[
        //   [
        //     { name: '聚酯级乙二醇', "value|1-100":  100},
        //     { name: '草酸二甲酯重成分 ',  "value|1-100":  100},
        //     { name: '已工业级碳酸 二甲酯',  "value|1-100":  100 },
        //     { name: '工业级乙二醇',  "value|1-100":  100},
        //     { name: '轻质油', "value|1-100":  100},
        //   ],
        // ]})
        res(Mock.mock(dataset));
    })
}

export const getLineChart:(type:PageDateSelect,date?:Date)=>Promise<IDateLineChart>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{
        const a=()=>(Math.random()*100).toFixed(2)
        const dataset:IDateLineChart={title:'产品类别销售占比',dataset:{dimensions:['date','实际','预测'],source:[{'date':'2021-01-7','实际':a(),'预测':a()},{'date':'2021-01-8','实际':a(),'预测':a()}]}}
        res(Mock.mock(dataset));
    })
}

export const getMapChinaChart:(ype:PageDateSelect,date?:Date)=>Promise<IDateLineChart>=function(type:PageDateSelect,date){
  return new Promise((res,rej)=>{
    const a=()=>(Math.random()*2000).toFixed(2)
    const dataset:IDateLineChart={title:'',dataset:{dimensions:['地区','数值'],
    source:[{'地区':'北京','数值':a()},
    {'地区':'上海','数值':a()},
    {'地区':'湖北','数值':a()},
    {'地区':'河北','数值':a()},
    {'地区':'新疆','数值':a()},
    {'地区':'甘肃','数值':a()},
    {'地区':'内蒙古','数值':a()},
    {'地区':'黑龙江','数值':a()},
    {'地区':'辽宁','数值':a()},
    {'地区':'陕西','数值':a()},
    {'地区':'山西','数值':a()},
    {'地区':'湖南','数值':a()},
    {'地区':'广西','数值':a()},
    {'地区':'江西','数值':a()},
    {'地区':'福建','数值':a()},
    {'地区':'浙江','数值':a()},
    {'地区':'广东','数值':a()},
    {'地区':'青海','数值':a()},
    {'地区':'吉林','数值':a()},
    {'地区':'海南','数值':a()},
    {'地区':'桂林','数值':a()},
    {'地区':'河南','数值':a()},
    {'地区':'天津','数值':a()},
    {'地区':'江苏','数值':a()},
    {'地区':'山东','数值':a()},
    {'地区':'四川','数值':a()},
    {'地区':'西藏','数值':a()},
  ]}}
    res(Mock.mock(dataset));

  })
}
